package com.example.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.aliyun.alink.business.login.IOpenLoginAdaptor;
import com.aliyun.alink.business.login.OpenLoginBusiness;
import com.example.AliSDK.CustomerLogin;
import com.example.openademo.R;
import com.taobao.weex.IWXRenderListener;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.WXRenderStrategy;
import com.taobao.weex.utils.WXFileUtils;
import com.taobao.weex.utils.WXViewUtils;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by Administrator on 2016-7-24.
 */
public class WeexActivity extends Activity{
    RelativeLayout viewGroup;
    CustomerLogin customerLogin = new CustomerLogin();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.weex);
        super.onCreate(savedInstanceState);

        WXSDKInstance mInstance = new WXSDKInstance(this);
        viewGroup = (RelativeLayout)findViewById(R.id.view_group);
        mInstance.registerRenderListener(new IWXRenderListener() {
            @Override
            public void onViewCreated(WXSDKInstance instance, View view) {
                viewGroup.addView(view);
            }

            @Override
            public void onRenderSuccess(WXSDKInstance instance, int width, int height) {

            }

            @Override
            public void onRefreshSuccess(WXSDKInstance instance, int width, int height) {

            }

            @Override
            public void onException(WXSDKInstance instance, String errCode, String msg) {

            }
        });
        renderPage(mInstance,getPackageName(), WXFileUtils.loadFileContent("login.js",this),null,null);
        OpenLoginBusiness.init(this,customerLogin);
    }

    protected void renderPage(WXSDKInstance mInstance,String packageName,String template,String source,String jsonInitData){
        Map<String, Object> options = new HashMap<>();
        options.put(WXSDKInstance.BUNDLE_URL, source);
        mInstance.render(
                packageName,
                template,
                options,
                jsonInitData,
                WXViewUtils.getScreenWidth(this),
                WXViewUtils.getScreenHeight(this),
                WXRenderStrategy.APPEND_ASYNC);
    }

}
